<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="扣分明细" width="1300px" @ok="handleSubmit" destroyOnClose>
    <!-- <BasicTable @register="registerTable" :search="false"  > -->
    <BasicTable  :columns="scoreColumn" :dataSource="dataSource" :pagination="false">
       
    </BasicTable>
    <!-- <ScoreSelectModal @register="regModal" @getSelectResult="setValue" v-bind="getBindValue" ></ScoreSelectModal> -->


  </BasicModal>
</template>
<script lang="ts" setup>
  import { ref, unref, toRaw, } from 'vue';
  import { BasicModal, useModalInner } from '/src/components/Modal';
  import { BasicTable, useTable, TableAction } from '/src/components/Table';
  import ScoreSelectModal from './ScoreSelectModal.vue'
  import { useListPage } from '/@/hooks/system/useListPage'
  import { useModal } from '/@/components/Modal';
  import { useAttrs } from '/@/hooks/core/useAttrs';
  import { scoreColumns, scoreSearchFormSchema } from '../DormScore.data';
  import { scorelist ,dormScoreHealthListApi,} from '../DormScore.api';
  
 // 声明Emits
  const emit = defineEmits(['select', 'register']);
  const checkedKeys = ref<Array<string | number>>([]);
  const [regModal, { openModal }] = useModal();
  const attrs = useAttrs();
  const getBindValue = ref({});
  const selectOptions = ref([]);
  const rowId = ref('')
  const [registerModal, { setModalProps, closeModal }] = useModalInner(async(data)=>{
     //重置表单
     console.log(data.record);
     rowId.value =  data.record.id
     getList(data.record.id)
    // setProps({ searchInfo: { id: data.record.id } });
    // reload();
  });
  let dataSource = ref([])
  let scoreColumn =ref([
  {
   title: '扣分项',
   align:"center",
   dataIndex: 'itemName'
  },
  {
   title: '得分',
   align:"center",
   dataIndex: 'score'
  },
  {
   title: '备注',
   align:"center",
   dataIndex: 'itemRemark'
  },
])
  //注册table数据
 const { tableContext,onExportXls,onImportXls } = useListPage({
      tableProps:{
           title: '设置得分项',
           api: dormScoreHealthListApi,
           columns :scoreColumns,
           canResize:false,
           rowKey:'id',
           formConfig: {
              labelWidth: 65,
              // schemas: scoreSearchFormSchema,
              autoSubmitOnEnter:true,
              showAdvancedButton:true,
              fieldMapToNumber: [
              ],
              fieldMapToTime: [
              ],
            },
            showActionColumn:false,
           actionColumn: {
               width: 220,
               fixed:'right'
            },
      },
     
  })
  const [registerTable, {getForm,setProps},{  }] = tableContext
  const tag = ref(false);
  function getList(id){
    dormScoreHealthListApi({id}).then(res=>{
      console.log(res);
      dataSource.value = res
    })
  }

  function handleOpen() {
        tag.value = true;
        openModal(true, {
          isUpdate: false,
        });
  }
  let selectValues = ref({
        value: [],
        change: false,
  })
  let scoreItemIds = ref('')
// const [state] = useRuleFormItem(props, 'value', 'change', emitData);
  function setValue(options, values) {
        selectOptions.value = options;
        //emitData.value = values.join(",");
        // state.value = values;
        selectValues.value = values;
        //update-begin-author:liusq date:20230517 for:选择职务组件v-model方式绑定值不生效
        scoreItemIds.value = values.join(',')
        console.log(scoreItemIds.value);
        // PersonMandesave({
        //   rowId:rowId.value,
        //   managerId:scoreItemIds.value
        // }).then(res=>{
        //   reload()
        // })
        // emit('update:value', values.join(','));
        //update-begin-author:liusq date:20230517 for:选择职务组件v-model方式绑定值不生效

  }
  /**
   * 选择列配置
   */
  const rowSelection = {
    type: 'checkbox',
    columnWidth: 50,
    selectedRowKeys: checkedKeys,
    onChange: onSelectChange,
  };
  /**
   * 选择事件
   */
  function onSelectChange(selectedRowKeys: (string | number)[]) {
    checkedKeys.value = selectedRowKeys;
  }

  //提交事件
  function handleSubmit() {
    setModalProps({ confirmLoading: true });
    //关闭弹窗
    closeModal();
    //刷新列表
    emit('select', toRaw(unref(checkedKeys)));
    setModalProps({ confirmLoading: false });
  }
  
   async function handleDelete(record) {
    //  await PersonMandeleteOne({id: record.id}, reload);
   }

</script>
